package me.wangxuan.pat;

import javax.swing.*;
import javax.swing.plaf.IconUIResource;
import java.awt.*;
import java.util.Enumeration;

public class UIDefaultsIconsExample extends JFrame {
    public UIDefaultsIconsExample() {
        setTitle("UIDefaults Icons Example");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null); // Center the window

        // 创建一个面板
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 2)); // 两列的网格布局

        // 获取 UIDefaults 实例
        UIDefaults uiDefaults = UIManager.getDefaults();

        // 遍历 UIDefaults 中的所有键值对
        Enumeration<Object> keys = uiDefaults.keys();
        while (keys.hasMoreElements()) {
        	Object o = keys.nextElement();
//        	System.out.println(o);
        	if(o instanceof String) {
        		String key = (String) o;
                Object value = uiDefaults.get(key);

                // 检查值是否是图标
                if (value instanceof Icon) {
                	System.out.println(key);
                    Icon icon = (Icon) value;
//                    System.out.println(icon);
//                    JLabel label = new JLabel(key, icon, SwingConstants.LEFT);
//                    panel.add(label);
                }
        	}
            
        }

        // 添加面板到 JFrame
        Container contentPane = getContentPane();
        contentPane.add(new JScrollPane(panel));
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            UIDefaultsIconsExample example = new UIDefaultsIconsExample();
            example.setVisible(true);
        });
    }
}
